<template>
  <div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="false"
      :row-selection="rowSelection"
      :customRow="handleClickRow"
      :row-class-name="tableRowClassName"
      style='height: 300px;overflow-x: hidden; overflow-y: auto;'
    >
    </a-table>
    <ProjectModal ref="modalForm" @onSelect='onSelect'></ProjectModal>
  </div>
</template>

<script>
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import ProjectModal from './ProjectModal.vue'
  import columns from './indexColumns'

  export default {
    name: 'AssistModal',
    mixins: [JeecgListMixin],
    components: {
      ProjectModal
    },
    data() {
      return {
        queryParam: {},
        // 表头
        columns: columns(this),
        url: {
          list: '/sjzxzy/sjZxzyAssistAccount/queryAssistList',
        },
        reportIds: [],
        checkedKeys: [],
        checkedRows: {}
      }
    },
    created() {

    },
    mounted() {

    },
    computed: {
      rowSelection() {
        return {
          type: 'radio',
          onChange: (selectedRowKeys, selectedRows) => {
            this.reportIds = []
            this.checkedKeys = selectedRowKeys
            this.checkedRows = selectedRows
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
            this.$emit('input', selectedRows[0].assistCode)
            this.$emit('sendAssisCode', selectedRows[0])
          }
        }
      }
    },
    methods: {
      openSearchModel(record){
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.isCheck = false;
        this.$refs.modalForm.disableSubmit = false;
      },
      handleClickRow(record, index){
        return {
          on: {
            click: () => {
              console.log(111,record)
              if(this.checkedKeys != [] && this.checkedKeys[0] == record.id){
                this.openSearchModel(record)
              }
            }
          }
        }
      },
      onSelect(val){
        let index = this.checkedRows[0].index
        // let assistType = this.dataSource[index].assistCode
        // let assistName = this.dataSource[index].assistName
        let assistCode = val.assCode

        this.dataSource[index].assistItemCode = val.assCode
        this.dataSource[index].assistItemName = val.assName
        this.$emit('onSelectAssist', assistCode)
      },
      updateList(){
        this.loadData(1)
      },
      tableRowClassName(record, index) {
        record.index = index
      },
    }
  }
</script>
<style scoped>

</style>